package com.kingwang.training.designpattern.adapter;

import com.kingwang.training.designpattern.adapter.bo.ChnVoltage;
import com.kingwang.training.designpattern.adapter.bo.ChnVoltageImpl;
import com.kingwang.training.designpattern.adapter.bo.UsaElectricCooker;
import com.kingwang.training.designpattern.adapter.bo.UsaVoltage;
import com.kingwang.training.designpattern.adapter.bo.inheritance.PowerClassAdapter;
import com.kingwang.training.designpattern.adapter.bo.instance.PowerAdapter;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application implements ApplicationRunner {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        classAdapter();

        instanceAdapter();
    }

    /**
     * 对象结构型
     */
    private void instanceAdapter() {
        ChnVoltage chnVoltage = new ChnVoltageImpl();

        UsaVoltage usaVoltage = new PowerAdapter(chnVoltage);

        UsaElectricCooker cooker = new UsaElectricCooker(usaVoltage);

        cooker.cook();
    }

    /**
     * 类结构型
     */
    private void classAdapter() {
        UsaVoltage voltage = new PowerClassAdapter();

        UsaElectricCooker cooker = new UsaElectricCooker(voltage);

        cooker.cook();
    }
}
